<template>
	<!-- <view class="content">
		<block v-for="(item, index) in dispatchers" :key="index">
			<view class="img">
				<image :src="item.img"></image>
			</view>
			<view class="info">
				<view>123</view>
				<view>123</view>
			</view>
			<view 
			:style="{display:'flex', alignItems:'center',justifyContent:'space-between',padding:'20rpx 0 40rpx 0'}">
				<button @click="open(item.id,item.status)" type="default"
					:style="{borderRadius:'30rpx', backgroundColor:'#FEB140',fontSize:'24rpx',margin:'0 30rpx 0 0'}">选择</button>
			</view>
		</block>
	</view> -->
	<view>
		<block v-for="(item, index) in dispatchers" :key="index">
			<view class="order">
				<!-- <view class="it1">
						<image :src="item.img"></image>
					</view> -->
				<view>
					<view>{{ item.title }}</view>
					<view>{{ item.mobile }}</view>
				</view>

				<!-- <view :style="{display:'flex', alignItems:'center',justifyContent:'space-between',padding:'20rpx 0 40rpx 0'}"> -->
				<button type="default" @click="choose(item.id)" :style="{ borderRadius: '30rpx', backgroundColor: '#FEB140', fontSize: '24rpx', margin: '0 30rpx 0 0' }">
					选择
				</button>
				<!-- </view> -->
			</view>
		</block>
		<navigator url="/pages/dispatcher/add/add">
			<button type="default" style="width: 710rpx;height: 92rpx;background-color: #FEB140;border-radius: 20rpx;color: #fff;font-size: 32rpx;font-weight: bold;margin-top: 150rpx;">添加配送员</button>
		</navigator>
	</view>
</template>

<script>
import { Storage } from '@/static/libs/utils';
export default {
	data() {
		return {
			dispatchers: [],
			token: '',
			foodId: '',
			dispatcherId: ''
		};
	},
	onLoad(option) {
		this.token = Storage.get('token');
		// console.log(JSON.parse(option.id));
		this.foodId = JSON.parse(option.id);
	},
	onShow() {
		this.getDispatcherList();
	},
	methods: {
		// 获取配送员列表
		getDispatcherList() {
			this.$request
				.post(
					`/waimai_go/web/wmerchant.php?c=site&a=entry&ctrl=store&ac=order&op=takeout&ta=select_deliveryer&do=web&m=we7_wmall&id=73&i=1&_=1624587309788&token=${
						this.token
					}&isajax=1`
				)
				.then(res => {
					console.log(35, res);
					this.dispatchers = res.data.data;
				});
		},

		// 选择配送员
		choose(id) {
			// console.log(75,id);
			this.$request
				.post(
					`/waimai_go/web/wmerchant.php?c=site&a=entry&ctrl=store&ac=order&op=takeout&ta=set_deliveryer&do=web&m=we7_wmall&id=${
						this.foodId
					}&deliveryer_id=${id}&i=1&token=${this.token}&isajax=1`
				)
				.then(res => {
					console.log('选择配送员', res);
					if (res.data.message.errno == 0) {
						uni.showToast({
							title: '操作成功',
							duration: 1500,
							icon: 'success'
						});
						setInterval(function backTo() {
							uni.navigateBack({
								delta: -1
							});
						}, 1500);
					} else {
						uni.showToast({
							title: '操作失败',
							duration: 1500,
							icon: 'none'
						});
					}
				});
		}
	}
};
</script>

<style lang="scss" scoped>
page {
	background: rgb(245, 245, 245);
}
.order{
	display: flex;
	justify-content: space-between;
	align-items: center;
	margin: 30rpx ;
	line-height: 70rpx;
	border: 1rpx solid #F1F1F1;
	border-radius: 15rpx;
}

</style>
